package com.al.Filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;


@WebFilter("/test")
public class WordFilter implements Filter {

	@Override
	public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
			throws IOException, ServletException {
		//将“敏感词”替换成“***”
		String test = req.getParameter("test");
		test = test.replaceAll("敏感词", "***");
		req.setAttribute("test", test);
		chain.doFilter(req, resp);
	}

}
